package com.example.fairplay.newfpregistration.ui;

import android.os.Bundle;
import android.support.v4.app.FragmentTransaction;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.LinearLayout;

import com.example.fairplay.newfpregistration.R;
import com.example.fairplay.newfpregistration.fragments.CheckFragment;
import com.example.fairplay.newfpregistration.fragments.FaceToFaceFragment;
import com.example.fairplay.newfpregistration.fragments.PickTestFragment;
import com.example.mylibrary.activity.BaseFragment;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by fairplay on 2018/6/1.
 */

public class MatchPickActivity extends BaseActivity2 {
    @Bind(R.id.fragment_container2)
    LinearLayout fragmentContainer2;
    @Bind(R.id.btn_pick_test)
    Button btnPickTest;
    @Bind(R.id.btn_face_comparison)
    Button btnFaceComparison;
    @Bind(R.id.btn_check)
    Button btnCheck;
    private MatchPickActivity mActivity;
    private Button[] mButtons;
    private int currentIndex = 0;
    private int index;
    private CheckFragment checkFragment;
    private PickTestFragment pickTestFragment;
    private FaceToFaceFragment faceToFaceFragment;
    private BaseFragment[] fragments;
    public static long sortId=0 ;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_match_pick);
        mActivity = this;
        ButterKnife.bind(this);
        initObject();
        initView();
        initData();
        setListener();
    }

    @Override
    protected void initData() {

    }

    @Override
    protected void initView() {
        mButtons = new Button[3];
        mButtons[0] = btnPickTest;
        mButtons[1] = btnFaceComparison;
        mButtons[2] = btnCheck;
        pickTestFragment = new PickTestFragment();
        faceToFaceFragment = new FaceToFaceFragment();
        checkFragment = new CheckFragment();
        fragments = new BaseFragment[]{pickTestFragment, faceToFaceFragment, checkFragment};
        mButtons[0].setSelected(true);
        getSupportFragmentManager().beginTransaction().add(R.id.fragment_container2, fragments[currentIndex]).show(pickTestFragment).commit();
        currentIndex = 0;
    }

    @Override
    protected void initObject() {

    }

    @Override
    protected void setListener() {


        for (Button button : mButtons) {
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Log.i("---", "onClick: 点击事件+1");
                    int id = view.getId();
                    if (id == R.id.btn_pick_test) {
                        index = 0;
                    } else if (id == R.id.btn_face_comparison) {
                        index = 1;
                    } else if (id == R.id.btn_check) {
                        index = 2;
                    }
                    if (currentIndex != index) {
                        FragmentTransaction fragmentTransaction = getSupportFragmentManager().beginTransaction();
                        fragmentTransaction.hide(fragments[currentIndex]);
                        if (fragments[index].isAdded()) {
                            fragmentTransaction.show(fragments[index]).commit();
                        } else {
                            fragmentTransaction.add(R.id.fragment_container2, fragments[index]).commit();
                        }
                        mButtons[currentIndex].setSelected(false);
                        mButtons[index].setSelected(true);
                    }
                    currentIndex = index;
                }
            });
        }
    }
/*
    @OnClick({R.id.btn_pick_test, R.id.btn_face_comparison, R.id.btn_check})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.btn_pick_test:
                Log.i("---log---", "onViewClicked: 1");
                break;
            case R.id.btn_face_comparison:
                Log.i("---log---", "onViewClicked: 2");
                break;
            case R.id.btn_check:
                Log.i("---log---", "onViewClicked: 3");
                break;
        }
    }*/
}
